package com.caidan.security.service.impl;

import com.caidan.security.domain.ResponseResult;
import com.caidan.security.domain.User;
import com.caidan.security.mapper.LoginMapper;
import com.caidan.security.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;

import java.util.Objects;


@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;


    @Autowired
    private AuthenticationManager authenticationManager;
    @Override
    public ResponseResult login(User user) {
        // 这个位置进行认证校验
        // 进行封装成UsernamePasswordAuthenticationToken对象 然后使用
        UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(),user.getPassword());

        Authentication authenticate = authenticationManager.authenticate(usernamePasswordAuthenticationToken);

        if(Objects.isNull(authenticate)){
            throw new RuntimeException("登录失败");
        }

        
        // 通过给出对应的提示
        return null;
    }
}
